﻿using Inventory.Business.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Inventory.Test
{   
    /// <summary>
    ///This is a test class for AdjustmentTransactionTest and is intended
    ///to contain all AdjustmentTransactionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AdjustmentTransactionTest
    {
        AdjustmentTransaction transaction = new AdjustmentTransaction();

       

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for GetById
        ///</summary>
        [TestMethod()]
        public void GetByIdTest()
        {
            var adj = transaction.GetById(53);

            Assert.IsNotNull(adj);
            Assert.AreNotEqual(0, adj.Items.Count);
        }

        /// <summary>
        ///A test for Edit
        ///</summary>
        [TestMethod()]
        public void EditTest()
        {
            var adj = transaction.GetById(53);

            //adj.Code += "!";
            adj.Items[0].Quantity += adj.Items[0].Quantity > 0 ? 1 : 0;
            adj.Items[0].Deduct += adj.Items[0].Deduct > 0 ? 1 : 0;

            Assert.IsTrue(transaction.Edit(adj));
        }

        /// <summary>
        ///A test for Create
        ///</summary>
        [TestMethod()]
        public void CreateTest()
        {
            var adj = new Inventory.Business.DomainObjects.Adjustment()
                {
                    //Code = "UTest",
                    CreationDate = DateTime.Now,
                    Status = Inventory.Business.DomainObjects.TransactionStatus.Open,
                    Warehouse = 4
                };

            adj.Items.Add(new Inventory.Business.DomainObjects.AdjMaterialItem()
            {
                Id = 19100,
                Quantity = 1,
                Area = Inventory.Business.DomainObjects.Area.OnSite
            });

            Assert.IsTrue(transaction.Create(adj));
        }

        /// <summary>
        ///A test for Commit
        ///</summary>
        [TestMethod()]
        public void CommitTest()
        {
            var adj = transaction.GetById(53);

            Assert.IsTrue(transaction.Commit(adj));
        }
    }
}
